#include "stdafx.h"
#include "collada.h"

#ifdef _DEBUG
#define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
#define new DEBUG_NEW
#endif

using namespace Collada;

IMPLEMENT_RTTI( Collada::Node, Collada::Element )
IMPLEMENT_ELEMENT( Collada::Node )

Node::Node( const std::string& id, const std::string& name )
:	Element( id, name )
{
	CHILD_ELEMENT_BEGIN()
		CHILD_ELEMENT( "asset",					Collada::Empty )
		CHILD_ELEMENT( "lookat",				Collada::Empty )
		CHILD_ELEMENT( "matrix",				Collada::Empty )
		CHILD_ELEMENT( "rotate",				Collada::Empty )
		CHILD_ELEMENT( "scale",					Collada::Empty )
		CHILD_ELEMENT( "skew",					Collada::Empty )
		CHILD_ELEMENT( "translate",				Collada::Empty )
		CHILD_ELEMENT( "instance_camera",		Collada::Empty )
		CHILD_ELEMENT( "instance_controller",	Collada::Empty )
		CHILD_ELEMENT( "instance_geometry",		Collada::Empty )
		CHILD_ELEMENT( "instance_light",		Collada::Empty )
		CHILD_ELEMENT( "instance_node",			Collada::Empty )
		CHILD_ELEMENT( "node",					Collada::Node )
		CHILD_ELEMENT( "extra",					Collada::Empty )
	CHILD_ELEMENT_END()
}

Node::~Node()
{
}

bool Node::AddChildNode( Node* pNode )
{
	_nodes.push_back( pNode );
	return true;
}

void Node::AllChildElementsLoaded( Element* pParent )
{
	if( pParent->IsA( VisualScene::GetTypeInfo() ) )
	{
		( ( VisualScene* )pParent )->AddNode( this );
	}

	if( pParent->IsA( Node::GetTypeInfo() ) )
	{
		( ( Node* )pParent )->AddChildNode( this );
	}
}

void Node::Initialize( Element* pParent, const void* desc )
{
	TiXmlElement* pElem = ( TiXmlElement* )desc;
	TiXmlElement* pChild = NULL;

	pChild = pElem->FirstChildElement( "instance_geometry" );
	if( pChild != NULL )
	{
		const char* url = pChild->Attribute( "url" );
		_instanceId = Fundamental::JenkinsPHF( &url[1] );
	}

}

bool Node::IsValid( const void* desc )
{
	return true;
}